//
//  DanLiPlayer.m
//  ExampleApp
//
//  Created by dllo on 15/8/10.
//  Copyright (c) 2015年 Thong Nguyen. All rights reserved.
//

#import "DanLiPlayer.h"

@implementation DanLiPlayer

- (void)dealloc
{

    [_indexpath release];
    [_dataArr release];
    [_durition release];
    [_pic_url release];
    [_song_singer release];
    [_song_name release];
    [_reDetailModel release];
    [super dealloc];
}


+ (DanLiPlayer *)shareHandleDanLiPlayer:(CGRect)Frame
{
    
    static DanLiPlayer *DanLi = nil;
    
    if (DanLi == nil) {
        
        // 初始化单例
        DanLi = [[DanLiPlayer alloc] initWithFrame:Frame];
        DanLi.backgroundColor = [UIColor clearColor];

        
        // 初始化播放模式 默认是顺序播放
        DanLi.playWays = 2;
        
        CGFloat Song_X = SCREEN_WIDTH*0.16; // 60
        CGFloat Song_Height = SCREEN_WIDTH*0.08;  // 30
        CGFloat Song_Width = SCREEN_WIDTH*0.42666; // 160
        
        // 歌曲名字
        DanLi.song_name = [[UILabel alloc] initWithFrame:CGRectMake(Song_X, 0, Song_Width, Song_Height)];
        DanLi.song_name.textAlignment = NSTextAlignmentLeft;
        DanLi.song_name.font = [UIFont boldSystemFontOfSize:15];
        DanLi.song_name.textColor = [UIColor whiteColor];
        [DanLi addSubview:DanLi.song_name];
        
        
        // 歌手名字
        CGFloat Durition_Height = SCREEN_WIDTH*0.05333; // 20
        DanLi.durition = [[UILabel alloc] initWithFrame:CGRectMake(Song_X, Song_Height, Song_Width, Durition_Height)];
        DanLi.durition.textColor = [UIColor whiteColor];
        DanLi.durition.font = [UIFont systemFontOfSize:14];
        [DanLi addSubview:DanLi.durition];
        
        
        
        
        // 播放按钮


        DanLi.Play = [UIButton buttonWithType:UIButtonTypeCustom];
        DanLi.Play.frame = CGRectMake(210*ADJUSTWIDTH, 1, 48, 48);
        [DanLi.Play setBackgroundImage:[UIImage imageNamed:@"play.png"] forState:0];
        [DanLi.Play setBackgroundImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
        [DanLi.Play addTarget:self action:@selector(PlayAction:)
             forControlEvents:UIControlEventTouchUpInside];
        [DanLi addSubview:DanLi.Play];
        
        
        
        // 下一曲

        DanLi.PlayNext = [UIButton buttonWithType:UIButtonTypeCustom];
        DanLi.PlayNext.frame = CGRectMake(270*ADJUSTWIDTH, 12, 26, 26);
        [DanLi.PlayNext setBackgroundImage:[UIImage imageNamed:@"xiayiquBar_32.png"]
                                  forState:UIControlStateNormal];
        [DanLi.PlayNext addTarget:self action:@selector(NextButton:)
                 forControlEvents:UIControlEventTouchUpInside];
        [DanLi addSubview:DanLi.PlayNext];
        
        
        // 列表按钮


        DanLi.ListButton = [UIButton buttonWithType:UIButtonTypeCustom];
        DanLi.ListButton.frame = CGRectMake(320*ADJUSTWIDTH, 12, 26, 26);
        [DanLi.ListButton addTarget:self action:@selector(ListAction:)
                   forControlEvents:UIControlEventTouchUpInside];        
        UIImage *list = [[UIImage imageNamed:@"liebiaoBar_32"]
                         imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [DanLi.ListButton setBackgroundImage:list forState:0];
        [DanLi addSubview:DanLi.ListButton];
        
        
        // 弹出播放阿牛
        DanLi.mainPlayView = [UIButton buttonWithType:UIButtonTypeCustom];
        DanLi.mainPlayView.backgroundColor = [UIColor orangeColor];
        DanLi.mainPlayView.frame = CGRectMake(2, 2, 46, 46);
        [DanLi.mainPlayView addTarget:self action:@selector(mainPlayView:)
                     forControlEvents:UIControlEventTouchUpInside];
        [DanLi.mainPlayView setBackgroundImage:[UIImage imageNamed:@"bofang_meitu_1.jpg"] forState:0];
        [DanLi addSubview:DanLi.mainPlayView];
        DanLi.dataArr = [NSMutableArray array];
        
    }
    return DanLi;
    
}



// 获取 当前歌曲
- (void)setReDetailModel:(ReDetailModel *)reDetailModel
{
    
    if (_reDetailModel != reDetailModel) {
        [_reDetailModel release];
        _reDetailModel = [reDetailModel retain];
    }
    
    if (reDetailModel.singerName) {
        self.song_name.text = reDetailModel.name;
        self.durition.text = reDetailModel.singerName;
        
    } else {
        self.song_name.text = reDetailModel.song_name;
        self.durition.text = reDetailModel.singer_name;
    }
    [self.Play setBackgroundImage:[UIImage imageNamed:@"pause.png"] forState:0];

}




// 播放页面开始出现
+ (void)mainPlayView:(UIButton *)sender
{
    DanLiPlayer *player = [DanLiPlayer shareHandleDanLiPlayer:CGRectZero];
    [player.delegate mainViewAppear:player.dataArr index:player.index playWays:player.playWays];
}


// 下一曲
+ (void)NextButton:(UIButton *)sender;
{
    DanLiPlayer *player = [DanLiPlayer shareHandleDanLiPlayer:CGRectZero];
    [player.delegate nextMusicButton:player.dataArr index:player.index];
    
}


// 播放列表界面
+ (void)ListAction:(UIButton *)sender
{
    NSLog(@"List");
    DanLiPlayer *player = [DanLiPlayer shareHandleDanLiPlayer:CGRectZero];
    [player.delegate changeView:player.reDetailModel dataArr:player.dataArr];
    
}


// 播放方法
+ (void)PlayAction:(UIButton *)sender
{
    [[DanLiPlayer shareHandleDanLiPlayer:CGRectZero].delegate playButton:sender];
}








/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
